package com.article.service.test;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/4.
 */
public class B {
    public static void main(String[] args) {
        String content = "<p>而且</p><p><img src=\"/ueditor/jsp/upload/image/20170504/1493873905159079944.png\" title=\"1493873905159079944.png\" width=\"171\" height=\"121\"/></p><p><img src=\"/ueditor/jsp/upload/image/20170504/1493873905282082582.png\" title=\"1493873905282082582.png\"/></p><p><br/></p>";
        Document doc = Jsoup.parse(content);
        Elements jpgs = doc.select("img[src~=(?i)\\.(png|jpe?g)]"); //　查找扩展名img[src$=.jpg]是jpg的图片
        List<String> imagesList = new ArrayList<String>();
        for (int i = 0; i < jpgs.size(); i++) {
            Element jpg = jpgs.get(i);
            imagesList.add(jpg.toString());
            if (i == 2) {
                break;
            }
        }
        for (String s : imagesList) {
            System.out.println(s);
        }
    }
}
